<template>
  <div class="share-container">
    <div class="share-header">
      <h1>分享你的故事</h1>
      <p>在这里分享你的情感经历，获得专业建议和网友支持</p>
    </div>

    <div class="share-content">
      <form @submit.prevent="submitStory" class="share-form card">
        <div class="form-group">
          <label for="title">标题 *</label>
          <input 
            type="text" 
            id="title" 
            v-model="storyForm.title" 
            placeholder="简明扼要地概括你的问题"
            required
          >
        </div>

        <div class="form-group">
          <label for="category">问题分类 *</label>
          <select id="category" v-model="storyForm.category" required>
            <option value="">请选择问题分类</option>
            <option v-for="category in categories" :key="category.id" :value="category.id">
              {{ category.name }}
            </option>
          </select>
        </div>

        <div class="form-group">
          <label for="content">详细描述 *</label>
          <textarea 
            id="content" 
            v-model="storyForm.content" 
            rows="8"
            placeholder="详细描述你遇到的问题，包括背景、经过和你的困惑。越详细越容易获得有价值的建议。"
            required
          ></textarea>
        </div>

        <div class="form-group">
          <label for="tags">标签 (可选)</label>
          <input 
            type="text" 
            id="tags" 
            v-model="storyForm.tags" 
            placeholder="输入标签，用逗号分隔（如：恋爱,沟通,信任）"
          >
        </div>

        <div class="form-actions">
          <button type="submit" class="btn btn-primary">发布故事</button>
          <button type="button" class="btn btn-secondary" @click="resetForm">重置</button>
        </div>
      </form>

      <div class="tips-section">
        <div class="tip-card card">
          <h3>分享建议</h3>
          <ul>
            <li>描述问题时尽量客观，避免情绪化语言</li>
            <li>保护隐私，不要透露真实姓名、地址等敏感信息</li>
            <li>详细描述有助于获得更准确的建议</li>
            <li>保持开放心态，认真考虑收到的建议</li>
          </ul>
        </div>

        <div class="tip-card card">
          <h3>社区规范</h3>
          <ul>
            <li>尊重他人，避免人身攻击</li>
            <li>建议要有建设性，避免无意义评论</li>
            <li>不传播虚假信息或谣言</li>
            <li>遵守法律法规，不发布违法内容</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ShareView',
  data() {
    return {
      storyForm: {
        title: '',
        category: '',
        content: '',
        tags: ''
      },
      categories: [
        { id: 1, name: '恋爱问题' },
        { id: 2, name: '分手问题' },
        { id: 3, name: '婚姻问题' },
        { id: 4, name: '暗恋问题' },
        { id: 5, name: '友情问题' }
      ]
    }
  },
  methods: {
    submitStory() {
      // 表单验证
      if (!this.storyForm.title || !this.storyForm.category || !this.storyForm.content) {
        alert('请填写所有必填项');
        return;
      }

      // 模拟提交成功
      alert('故事发布成功！感谢你的分享。');
      this.resetForm();
      
      // 在实际应用中，这里会发送请求到服务器
      // this.$api.post('/stories', this.storyForm)
      //   .then(response => {
      //     alert('故事发布成功！感谢你的分享。');
      //     this.resetForm();
      //   })
      //   .catch(error => {
      //     alert('发布失败，请稍后重试');
      //   });
    },
    resetForm() {
      this.storyForm = {
        title: '',
        category: '',
        content: '',
        tags: ''
      };
    }
  }
}
</script>

<style scoped>
.share-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.share-header {
  text-align: center;
  margin-bottom: 2rem;
}

.share-header h1 {
  font-size: 2.5rem;
  color: #333;
  margin-bottom: 1rem;
}

.share-header p {
  color: #666;
  font-size: 1.1rem;
}

.share-content {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
}

.share-form {
  background-color: #fff;
  border-radius: 10px;
  padding: 2rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
  color: #333;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.8rem;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #ff9a9e;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

.tips-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.tip-card {
  background-color: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.tip-card h3 {
  font-size: 1.3rem;
  color: #333;
  margin-bottom: 1rem;
}

.tip-card ul {
  padding-left: 1.5rem;
}

.tip-card li {
  margin-bottom: 0.5rem;
  color: #666;
  line-height: 1.6;
}

@media (max-width: 992px) {
  .share-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .share-container {
    padding: 1rem;
  }
  
  .share-header h1 {
    font-size: 2rem;
  }
  
  .share-form {
    padding: 1.5rem;
  }
  
  .form-actions {
    flex-direction: column;
  }
}
</style>